﻿// Copyright (c) 2012 Mokah Nnamezie & Andrew Cooper
// Neo4Net graph database - http://neo4net.codeplex.com
//
// This file is part of Neo4Net - a .Net port of the Neo4j graph database
//
// Neo4Net is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

namespace Neo4Net.Kernel.Configuration
{
    using Neo4Net.Helpers.Collection;
    using Neo4Net.Kernel.Impl.Util;
    using NUnit.Framework;

    // Test configuration migration rules
    [TestFixture]
    public class ConfigurationMigratorTest
    {
        [Test]
        public void TestNoMigration()
        {
            ConfigurationMigrator migrator = new ConfigurationMigrator(StringLogger.SYSTEM);
            Assert.That(migrator.MigrateConfiguration(DictionaryUtil.StringMap("foo", "bar")), Is.EqualTo(DictionaryUtil.StringMap("foo", "bar")));
        }

        [Test]
        public void TestEnableOnlineBackup()
        {
            ConfigurationMigrator migrator = new ConfigurationMigrator(StringLogger.SYSTEM);
            Assert.That(migrator.MigrateConfiguration(DictionaryUtil.StringMap("enable_online_backup", "true")), Is.EqualTo(DictionaryUtil.StringMap("online_backup_enabled", "true", "online_backup_port", "6362")));
        }

        [Test]
        public void TestUdcEnabled()
        {
            ConfigurationMigrator migrator = new ConfigurationMigrator(StringLogger.SYSTEM);
            Assert.That(migrator.MigrateConfiguration(DictionaryUtil.StringMap("neo4j.ext.udc.disable", "true")), Is.EqualTo(DictionaryUtil.StringMap("neo4j.ext.udc.enabled", "false")));
            Assert.That(migrator.MigrateConfiguration(DictionaryUtil.StringMap("neo4j.ext.udc.disable", "false")), Is.EqualTo(DictionaryUtil.StringMap("neo4j.ext.udc.enabled", "true")));
        }

        [Test]
        public void TestEnableRemoteShell()
        {
            ConfigurationMigrator migrator = new ConfigurationMigrator(StringLogger.SYSTEM);
            Assert.That(migrator.MigrateConfiguration(DictionaryUtil.StringMap("enable_remote_shell", "true")), Is.EqualTo(DictionaryUtil.StringMap("remote_shell_enabled", "true")));
            Assert.That(migrator.MigrateConfiguration(DictionaryUtil.StringMap("enable_remote_shell", "false")), Is.EqualTo(DictionaryUtil.StringMap("remote_shell_enabled", "false")));
            Assert.That(migrator.MigrateConfiguration(DictionaryUtil.StringMap("enable_remote_shell", "port=1234")), Is.EqualTo(DictionaryUtil.StringMap("remote_shell_enabled", "true", "remote_shell_port", "1234", "remote_shell_read_only", "false", "remote_shell_name", "shell")));
        }
    }
}
